package bankapp.get;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class BankUser extends Activity{

	 private Button balance,transaction,fund,change;
	 String username;
	 TextView tv;
	 private TodoDbAdapter mDbHelper;
	 private Table table = null;
	 private Long mRowId;
	 Cursor c;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.usermove);
		this.balance=(Button)this.findViewById(R.id.button1);
		this.fund=(Button)this.findViewById(R.id.button2);
		this.transaction=(Button)this.findViewById(R.id.button3);
		this.change=(Button)this.findViewById(R.id.button4);
		this.tv=(TextView)this.findViewById(R.id.display);
		Bundle bundle=getIntent().getExtras();
		
		username=(String)bundle.getString("user");
		tv.setText("Welcome "+username);
		
		mDbHelper = new TodoDbAdapter(this);
        mDbHelper.open();
        c=mDbHelper.fetchAllTodos();
        startManagingCursor(c);
        
		balance.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                //setResult(RESULT_OK);
                //finish();
             balance();           
            	
            }

        });
		transaction.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                //setResult(RESULT_OK);
                //finish();
             transact();           
            	
            }

        });
		fund.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                //setResult(RESULT_OK);
                //finish();
             fund();           
            	
            }

        });
		change.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                //setResult(RESULT_OK);
                //finish();
             change();           
            	
            }

        });
		
	}
	public void balance()
	{
		
    	int balance=0;
    	while(c.moveToNext())
        {
    		if(c.getString(1).equals(username))
    		{
    			 			
    			balance=c.getInt(4);
    			break;
    		}
        }
    	Intent move=new Intent();
    	move.setClass(this, balance.class);
    	move.putExtra("user", username);
    	System.out.println("balance is "+balance);
    	move.putExtra("balance",balance);
		
    	startActivity(move);	
    	
    	
	}
	public void transact()
	{
		
	}
	public void fund()
	{
		Intent fmove=new Intent();
		fmove.setClass(this, FundTransfer.class);
		fmove.putExtra("user", username);
		startActivity(fmove);
		
	}
	public void change()
	{
		
	}
	

}
